// pages/assessment/assessment.js
var app = getApp();
var ea = require('../../utils/each.js');
var time = require('../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tijiaopingjia: app.data.url + '/zhongxue/teacher/tijiaopingjia',
    gettoken: app.data.url + '/zhongxue/teacher/gettoken',
    shuju: {},
    testpaper: [],
    xiaxiaurl: '/img/26.png',
    titles:[
      {
        url:"/img/26.png",
        name:"陈雪"
      },
      {
        url: "/img/26.png",
        name: "陈雪"
      }, {
        url: "/img/26.png",
        name: "陈雪"
      },
      {
        url: "/img/26.png",
        name: "陈雪"
      },
      {
        url: "/img/26.png",
        name: "陈雪"
      },
       {
        url: "/img/26.png",
        name: "陈雪"
      }, 
      {
        url: "/img/26.png",
        name: "陈雪"
      },
       {
        url: "/img/26.png",
        name: "陈雪"
      }
    ],



    ardioTile:[
      {
        id:0,
        ardioUrl: app.data.url +"uploads/laoshi/2bff1c178ed3c6f6fe1a4a212754f50.png",
        uname:"优秀"
      },
      {
        id:1,
        ardioUrl: app.data.url +"uploads/laoshi/beb7a68af67bc7523a4c0177356b8c3.png",
        uname: "良好"
      },
      {
        id:2,
        ardioUrl: app.data.url +"uploads/laoshi/19c7df19c1ed0cc19ac392a1b4fcef7.png",
        uname: "中等"
      },
      {
        id:3,
        ardioUrl: app.data.url +"uploads/laoshi/eec5f977bedf428778942adaee35a61.png",
        uname: "较差"
      }
    ]
  },

  dianji:function(e){
    // console.log(e);
    var dengji = e.currentTarget.dataset.id;
    // console.log(dengji)
    var shuju = this.data.shuju;
    shuju['dengji'] = dengji
    console.log(shuju)
  },

  //获取input框所有内容
  inputWacth: function (e) {
    // console.log(e);
    let item = e.currentTarget.dataset.model;
    // console.log(item);
    var shuju = this.data.shuju;
    var user = wx.getStorageSync('newuser');
    shuju[item] = e.detail.value;
    // console.log(shuju[item])
    shuju['teacher_id'] = user.id;
    this.setData({ shuju: shuju });
    this.setData({
      [item]: e.detail.value
    });
    console.log(shuju)
  },

  /**
   * 删除学生
   */
  shanchu: function (e) {
    // console.log(e)
    var index = e.currentTarget.dataset.index;
    var titles = this.data.titles;
    var newtitles = [];
    ea.each(titles, function (i, v) {
      if (i !== index) {
        newtitles.push(v);
        // console.log(v);
      }
    })
    this.setData({ titles: newtitles })
    console.log(newtitles);
    var shuju = this.data.shuju;
    // ea.each(newtitles,function(v){
    //   shuju['student_id'] = newtitles['id'];
    // })
    // this.setData({ shuju : newtitles})
    // shuju['student_id'] = newtitles;
    console.log(shuju);
  },

/**
 * 提交评价
 */
  tijiao:function(){
    var that = this;
    var shuju = that.data.shuju;
    // console.log(user)
    // var token = user.token;
    // var shenhe = user.shenhe;
    var yanz = ea.yanzhen(shuju, {
      dir: '请输入老师评语',
      dengji: '请选择表现等级',
      student_id: '请至少选择一个学生'
    })
    if (yanz) {
      wx.showToast({
        title: yanz,
        icon: 'none'
      })
      return;
    }
    wx.request({
      url: that.data.tijiaopingjia,
      data: shuju,
      method: 'post',
      success: function (res) {
        var data = res.data
        console.log(data)
        if (data.code == 200) {
          wx.showToast({
            title: '评价成功',
            icon: 'success',
          })
          setTimeout(function () {
            wx.navigateBack({
              delta: 1,
            })
          }, 1000)
        } else {
          wx.showToast({
            title: '评价失败',
            icon: 'none',
          })
        }
      }
    })
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var titles = wx.getStorageSync('pingjia');
    // console.log(titles);
    this.setData({ titles: titles })
    wx.setStorageSync('pingjia', null);
    var shuju = this.data.shuju;
    var studentid = [];
    // shuju['student_id'] = titles
    ea.each(titles, function (i, v) {
      studentid.push(v.id);
      // console.log(v);
    })
    shuju.student_id = studentid;
    console.log(shuju)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})